//
//  RankTableViewCell.swift
//  Spookiness
//
//  Created by 腾億 on 2017/12/11.
//  Copyright © 2017年 tml. All rights reserved.
//

import UIKit

class RankTableViewCell: UITableViewCell {

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.contentView.addSubview(self.lineView)
        self.contentView.addSubview(self.iconView)
        self.contentView.addSubview(self.titleLable)
        self.contentView.addSubview(self.descLabel)
        setUpSnap()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    fileprivate lazy var iconView: UIImageView = {
       let imgV = UIImageView()
        imgV.contentMode = .scaleAspectFill
        imgV.clipsToBounds = true
        return imgV
    }()
    
    fileprivate lazy var titleLable: UILabel = {
       let label = UILabel()
        label.textColor = UIColor.black
        label.font = UIFont.systemFont(ofSize: 18)
        return label
    }()
    
    fileprivate lazy var descLabel: UILabel = {
       let label = UILabel()
        label.textColor = UIColor.lightGray
        label.numberOfLines = 0
        label.font = UIFont.systemFont(ofSize: 14)
        return label
    }()
    
    fileprivate lazy var lineView: UIView = {
       let line = UIView()
        line.backgroundColor = kRGBA(r: 242, g: 242, b: 242, a: 1)
        return line
    }()
    
    fileprivate func setUpSnap() {
        self.lineView.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(10)
        }
        
        self.iconView.snp.makeConstraints { (make) in
            make.left.top.equalTo(self.contentView).offset(10)
            make.bottom.equalTo(self.lineView.snp.top).offset(-10)
            //设置icon宽度为contentView宽度的0.5倍
            make.width.equalToSuperview().multipliedBy(0.5)
        }
        
        self.titleLable.snp.makeConstraints { (make) in
            make.left.equalTo(self.iconView.snp.right).offset(10)
            make.right.equalToSuperview().offset(-10)
            make.height.equalTo(30)
            make.top.equalTo(self.iconView).offset(20)
        }
        
        self.descLabel.snp.makeConstraints { (make) in
            make.left.equalTo(self.iconView.snp.right).offset(10)
            make.right.equalToSuperview().offset(-10)
            make.top.equalTo(self.titleLable.snp.bottom).offset(10)
            make.bottom.equalTo(self.iconView)
        }
        
    }
    
    var rankModel: RankingModel? {
        didSet {
            guard rankModel != nil else {
                return
            }
            iconView.kf.setImage(urlString: rankModel?.cover ?? "")
            titleLable.text = "\(rankModel?.title ?? "")榜"
            descLabel.text = rankModel?.subTitle ?? ""
        }
    }
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
